﻿using dotUML.Core.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace CommonTest
{
    
    
    /// <summary>
    ///This is a test class for ModelTest and is intended
    ///to contain all ModelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ModelTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Model Constructor
        ///</summary>
        [TestMethod()]
        public void ModelConstructorTest()
        {
            Model target = new Model();
            Assert.IsNotNull(target.Errors);
            Assert.IsNotNull(target.Stereotypes);
            Assert.IsNotNull(target.Diagrams);
            Assert.IsNotNull(target.SequenceDiagramStructure);
            Assert.IsNotNull(target.ComponentDiagramStructure);
        }


        /// <summary>
        ///A test for GetStereotype
        ///</summary>
        [TestMethod()]
        public void GetStereotypeTest()
        {
            string stereoTypeName = "stereotype1";
            IModel target = ModelFactory.GetModel();

            IStereotype sAdded = target.AddStereotype(stereoTypeName);
            IStereotype s = target.GetStereotype(stereoTypeName);
            Assert.AreEqual(s.Name, stereoTypeName);
            Assert.AreSame(s, sAdded);

            s = target.GetStereotype("stereotype2");
            Assert.IsNull(s);
        }

        /// <summary>
        ///A test for DeleteStereotype
        ///</summary>
        [TestMethod()]
        public void DeleteStereotypeTest()
        {
            string stereotypeName = "stereotype1";
            IModel target = ModelFactory.GetModel();

            target.AddStereotype(stereotypeName);
            IStereotype s = target.GetStereotype(stereotypeName);
            Assert.IsNotNull(s);

            target.DeleteStereotype(stereotypeName);
            s = target.GetStereotype(stereotypeName);
            Assert.IsNull(s);
        }

        /// <summary>
        ///A test for AddStereotype
        ///</summary>
        [TestMethod()]
        public void AddStereotypeTest()
        {
            IModel target = ModelFactory.GetModel();
            
            IStereotype s1 = target.AddStereotype("stereotype1");
            Assert.IsNotNull(s1);

            IStereotype s2 = target.AddStereotype("stereotype2");
            Assert.IsNotNull(s2);

            try
            {
                IStereotype s3 = target.AddStereotype("stereotype1");
                Assert.Fail("It was possible to add a stereotype with the same name twice.");
            }
            catch (CommonException)
            {
            }
        }

        /// <summary>
        ///A test for GetSequenceDiagram
        ///</summary>
        [TestMethod()]
        public void GetSequenceDiagramTest()
        {
            string sequenceDiagramName = "sequenceDiagram1";
            IModel target = ModelFactory.GetModel();

            ISequenceDiagram sdAdded = target.AddSequenceDiagram(sequenceDiagramName);
            ISequenceDiagram s = target.GetSequenceDiagram(sequenceDiagramName);
            Assert.AreSame(s, sdAdded);
            Assert.AreEqual(s.Name, sequenceDiagramName);

            s = target.GetSequenceDiagram("sequenceDiagram2");
            Assert.IsNull(s);
        }

        /// <summary>
        ///A test for DeleteSequenceDiagram
        ///</summary>
        [TestMethod()]
        public void DeleteSequenceDiagramTest()
        {
            string sequenceDiagramName = "sequenceDiagram1";
            IModel target = ModelFactory.GetModel();

            target.AddSequenceDiagram(sequenceDiagramName);
            ISequenceDiagram s = target.GetSequenceDiagram(sequenceDiagramName);
            Assert.IsNotNull(s);

            target.DeleteSequenceDiagram(sequenceDiagramName);
            s = target.GetSequenceDiagram(sequenceDiagramName);
            Assert.IsNull(s);
        }

        /// <summary>
        ///A test for AddSequenceDiagram
        ///</summary>
        [TestMethod()]
        public void AddSequenceDiagramTest()
        {
            string sequenceDiagramName1 = "sequenceDiagram1";
            string sequenceDiagramName2 = "sequenceDiagram2";
            IModel target = ModelFactory.GetModel();

            ISequenceDiagram s1 = target.AddSequenceDiagram(sequenceDiagramName1);
            Assert.IsNotNull(s1);
            Assert.AreEqual(s1.Name, sequenceDiagramName1);
            Assert.AreEqual(s1.DiagramType, EDiagramType.Sequence);

            ISequenceDiagram s2 = target.AddSequenceDiagram(sequenceDiagramName2);
            Assert.IsNotNull(s2);
            Assert.AreEqual(s2.Name, sequenceDiagramName2);
            Assert.AreEqual(s2.DiagramType, EDiagramType.Sequence);

            try
            {
                ISequenceDiagram s3 = target.AddSequenceDiagram(sequenceDiagramName1);
                Assert.Fail("It was possible to add a sequence diagram with the same name twice.");
            }
            catch (CommonException)
            {
            }

        }
     }
}
